/*
 * author: ht
 * desc: 聊天所用到的服务接口
 */
var constant = require('../const');
var models = require('../models');
var AV = require('leanengine')

/*
 *actions:透传action
 *userId:发送给的人
 *nick:发送人的昵称
 */
function sendFriendApplyMsg(req, res) {
	var touserId = req.params.touserId;
	var fromuserId = req.params.fromuserId
	var nick = req.params.nick;
	var actions = req.params.actions || "com.pocketsweet.FRIEND_APPLY";
	if (actions == "com.pocketsweet.FRIEND_APPLY") {
		var msg = nick + "请求做您的好友";
	} else {
		var msg = nick + "同意了您的好友申请";
	}

	var tokenQuery = new AV.Query(models.HXToken);
	tokenQuery.descending("createdAt");
	tokenQuery.find({
		success: function(results) {
			var token = results[0].get('token');
			// 发送会话消息
			AV.Cloud.httpRequest({
				method: 'POST',
				url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/messages',
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer " + token
				},
				body: {
					"target_type": "users", // users 给用户发消息, chatgroups 给群发消息
					"target": [touserId], // 注意这里需要用数组,数组长度建议不大于20, 即使只有一个用户,   
					// 也要用数组 ['u1'], 给用户发送时数组元素是用户名,给群组发送时  
					// 数组元素是groupid
					"msg": {
						"type": "cmd",
						"action": actions
					},
					"from": "NEW_FRIEND", //表示这个消息是谁发出来的, 可以没有这个属性, 那么就会显示是admin, 如果有的话, 则会显示是这个用户发出的
					"ext": {
						"msg": msg,
						"from": fromuserId
					}
				},
				success: function(httpResponse) {
					res.success('发送成功');
				},
				error: function(httpResponse) {
					if (httpResponse.status == 401) {
						getHXToken();
					}
					res.error('发送失败');
				}
			});
		},
		error: function() {
			res.error('发送失败');
		}
	})
}

function sendFriendApplyMsgShow(req, res) {
	var touserId = req.params.touserId;
	var fromuserId = req.params.fromuserId
	var nick = req.params.nick;
	var msg = nick + "请求做您的好友";

	var tokenQuery = new AV.Query(models.HXToken);
	tokenQuery.descending("createdAt");
	tokenQuery.find({
		success: function(results) {
			var token = results[0].get('token');
			// 发送会话消息
			AV.Cloud.httpRequest({
				method: 'POST',
				url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/messages',
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer " + token
				},
				body: {
					"target_type": "users", // users 给用户发消息, chatgroups 给群发消息
					"target": [touserId], // 注意这里需要用数组,数组长度建议不大于20, 即使只有一个用户,   
					// 也要用数组 ['u1'], 给用户发送时数组元素是用户名,给群组发送时  
					// 数组元素是groupid
					"msg": {
						"type": "txt",
						"msg": msg //消息内容，参考[聊天记录](http://www.easemob.com/docs/rest/chatmessage/)里的bodies内容
					},
					"from": "NEW_FRIEND", //表示这个消息是谁发出来的, 可以没有这个属性, 那么就会显示是admin, 如果有的话, 则会显示是这个用户发出的    		    	    
				},
				success: function(httpResponse) {
					res.success('发送成功');
				},
				error: function(httpResponse) {
					res.error('发送失败');
				}
			});
		},
		error: function() {
			res.error('发送失败');
		}
	})
}

//普通人中的恋人申请和解除的透传
function sendSweetApplyCMDMsg(req, res) {
	var touserId = req.params.touserId;
	var fromuserId = req.params.fromuserId
	var nick = req.params.nick || "";
	var sweetId = req.params.sweetId || "";
	var actions = req.params.actions || constant.ACTION_SWEET_APPLY;
	if (actions == constant.ACTION_SWEET_APPLY) {
		var msg = nick + "请求做您的恋人";
	} else {
		var msg = nick + "同意了您的恋人申请";
	}

	var tokenQuery = new AV.Query(models.HXToken);
	tokenQuery.descending("createdAt");
	tokenQuery.find({
		success: function(results) {
			var token = results[0].get('token');
			// 发送会话消息
			AV.Cloud.httpRequest({
				method: 'POST',
				url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/messages',
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer " + token
				},
				body: {
					"target_type": "users", // users 给用户发消息, chatgroups 给群发消息
					"target": [touserId], // 注意这里需要用数组,数组长度建议不大于20, 即使只有一个用户,   
					// 也要用数组 ['u1'], 给用户发送时数组元素是用户名,给群组发送时  
					// 数组元素是groupid
					"msg": {
						"type": "cmd",
						"action": actions
					},
					"from": "NEW_SWEET", //表示这个消息是谁发出来的, 可以没有这个属性, 那么就会显示是admin, 如果有的话, 则会显示是这个用户发出的
					"ext": {
						"msg": msg,
						"from": fromuserId,
						"sweetId": sweetId
					}
				},
				success: function(httpResponse) {
					res.success('发送成功');
				},
				error: function(httpResponse) {
					if (httpResponse.status == 401) {
						getHXToken();
					}
					res.error('发送失败');
				}
			});
		},
		error: function() {
			res.error('发送失败');
		}
	})
}
//发送普通消息的方法
function sendSweetApplyMsg(req, res) {
	var touserId = req.params.touserId;
	var fromuserId = req.params.fromuserId
	var nick = req.params.nick;
	var msg = nick + "请求做您的恋人";

	var tokenQuery = new AV.Query(models.HXToken);
	tokenQuery.descending("createdAt");
	tokenQuery.find({
		success: function(results) {
			var token = results[0].get('token');
			// 发送会话消息
			AV.Cloud.httpRequest({
				method: 'POST',
				url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/messages',
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer " + token
				},
				body: {
					"target_type": "users", // users 给用户发消息, chatgroups 给群发消息
					"target": [touserId], // 注意这里需要用数组,数组长度建议不大于20, 即使只有一个用户,   
					// 也要用数组 ['u1'], 给用户发送时数组元素是用户名,给群组发送时  
					// 数组元素是groupid
					"msg": {
						"type": "txt",
						"msg": msg //消息内容，参考[聊天记录](http://www.easemob.com/docs/rest/chatmessage/)里的bodies内容
					},
					"from": "NEW_SWEET", //表示这个消息是谁发出来的, 可以没有这个属性, 那么就会显示是admin, 如果有的话, 则会显示是这个用户发出的    		    	    
				},
				success: function(httpResponse) {
					res.success('发送成功');
				},
				error: function(httpResponse) {
					res.error('发送失败');
				}
			});
		},
		error: function() {
			res.error('发送失败');
		}
	})
}

function getHXToken() {
	AV.Cloud.httpRequest({
		method: 'POST',
		url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/token',
		headers: {
			"Content-Type": "application/json",
		},
		body: {
			"grant_type": "client_credentials",
			"client_id": constant.HX_CLIENT_ID,
			"client_secret": constant.HX_CLIENT_SECRET
		},
		success: function(httpResponse) {
			var token = httpResponse.data.access_token;
			var hxToken = new models.HXToken;
			hxToken.set('token', token);
			hxToken.save(null, {
				success: function(token) {
					console.log(token.get('token'));
				},
				error: function(error) {
					console.log("shibai");
				}

			});
		},
		error: function(httpResponse) {
			console.log(httpResponse.status);
		}
	});
}

function register(req, res) {
	var username = req.params.username;
	var password = req.params.password;
	var nickname = req.params.nickname;
	AV.Cloud.httpRequest({
		method: 'POST',
		url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/users',
		headers: {
			"Content-Type": "application/json",
		},
		body: {
			"username": username,
			"password": password,
			"nickname": nickname
		},
		success: function(httpResponse) {
			res.success('注册成');
		},
		error: function(httpResponse) {
			res.error('发送失败');
		}
	});
}

function sendChatApplyMsg(req, res) {
	var touserId = req.params.touserId;
	var fromuserId = req.params.fromuserId
	var nick = req.params.nick;
	var msg = nick + "申请与您聊天";
	var tokenQuery = new AV.Query(models.HXToken);
	tokenQuery.descending("createdAt");
	tokenQuery.find({
		success: function(results) {
			var token = results[0].get('token');
			// 发送会话消息
			AV.Cloud.httpRequest({
				method: 'POST',
				url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/messages',
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer " + token
				},
				body: {
					"target_type": "users", // users 给用户发消息, chatgroups 给群发消息
					"target": [touserId], // 注意这里需要用数组,数组长度建议不大于20, 即使只有一个用户,   
					// 也要用数组 ['u1'], 给用户发送时数组元素是用户名,给群组发送时  
					// 数组元素是groupid
					"msg": {
						"type": "txt",
						"msg": msg //消息内容，参考[聊天记录](http://www.easemob.com/docs/rest/chatmessage/)里的bodies内容
					},
					"from": "NEW_CHAT_APPLY", //表示这个消息是谁发出来的, 可以没有这个属性, 那么就会显示是admin, 如果有的话, 则会显示是这个用户发出的  		    	    
				},
				success: function(httpResponse) {
					res.success('发送成功');
				},
				error: function(httpResponse) {
					if (httpResponse.status == 401) {
						getHXToken();
					}
					res.error('发送失败');
				}
			});
		},
		error: function() {
			res.error('发送失败');
		}
	})
}

function sendChatAgreeMsg(req, res) {
	var touserId = req.params.touserId;
	var fromuserId = req.params.fromuserId
	var nick = req.params.nick;
	var msg = nick + "同意了您的聊天申请";
	var tokenQuery = new AV.Query(models.HXToken);
	tokenQuery.descending("createdAt");
	tokenQuery.find({
		success: function(results) {
			var token = results[0].get('token');
			// 发送会话消息
			AV.Cloud.httpRequest({
				method: 'POST',
				url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/messages',
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer " + token
				},
				body: {
					"target_type": "users", // users 给用户发消息, chatgroups 给群发消息
					"target": [touserId], // 注意这里需要用数组,数组长度建议不大于20, 即使只有一个用户,   
					// 也要用数组 ['u1'], 给用户发送时数组元素是用户名,给群组发送时  
					// 数组元素是groupid
					"msg": {
						"type": "cmd",
						"action": "com.pocketsweet.CHAT_APPLY_ACCEPT"
					},
					"from": "NEW_CHAT_APPLY", //表示这个消息是谁发出来的, 可以没有这个属性, 那么就会显示是admin, 如果有的话, 则会显示是这个用户发出的
					"ext": {
						"msg": msg,
						"from": fromuserId
					}
				},
				success: function(httpResponse) {
					res.success('发送成功');
				},
				error: function(httpResponse) {
					if (httpResponse.status == 401) {
						getHXToken();
					}
					res.error('发送失败');
				}
			});
		},
		error: function() {
			res.error('发送失败');
		}
	})
}

function transferAccount(req, res) {
	var price = req.params.price || 0;
	var multiple = req.params.multiple || 0.7;
	var userId = req.params.userId;
	var userQuery = new AV.Query(models.MLUser);
	userQuery.get(userId, {
		success: function(user) {
			if (price == 0) {
				price = user.get('price');
			}
			var balance = user.get('balance') + price * multiple;
			user.set('balance', parseFloat(balance.toFixed(2)));
			user.save(null, {
				success: function(user) {
					res.success('转账成功');
				},
				error: function(user, error) {
					res.error(error);
				}
			})
		},
		error: function(error) {
			res.error('转账失败');
		}
	})
}

function newTransferAccount(req, res) {
	var price = req.params.price || 0;
	var multiple = req.params.multiple || 1;
	var userId = req.params.userId;
	var userQuery = new AV.Query(models.MLUser);
	userQuery.get(userId, {
		success: function(user) {
			if (price == 0) {
				price = user.get('price');
			}
			var balance = user.get('balance') + price * multiple;
			user.set('balance', parseFloat(balance.toFixed(2)));
			user.save(null, {
				success: function(user) {
					res.success('转账成功');
				},
				error: function(user, error) {
					res.error(error);
				}
			})
		},
		error: function(error) {
			res.error('转账失败');
		}
	})
}

function sendNewLikerMsg(req, res) {
	var touserId = req.params.touserId;
	var fromuserId = req.params.fromuserId
	var nick = req.params.nick;
	var actions = "com.pocketsweet.NEW_LIKER";
	var msg = nick + "给你点了赞哦";
	var tokenQuery = new AV.Query(models.HXToken);
	tokenQuery.descending("createdAt");
	tokenQuery.find({
		success: function(results) {
			var token = results[0].get('token');
			// 发送会话消息
			AV.Cloud.httpRequest({
				method: 'POST',
				url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/messages',
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer " + token
				},
				body: {
					"target_type": "users", // users 给用户发消息, chatgroups 给群发消息
					"target": [touserId], // 注意这里需要用数组,数组长度建议不大于20, 即使只有一个用户,   
					// 也要用数组 ['u1'], 给用户发送时数组元素是用户名,给群组发送时  
					// 数组元素是groupid
					"msg": {
						"type": "cmd",
						"action": actions
					},
					"from": "NEW_LIKER", //表示这个消息是谁发出来的, 可以没有这个属性, 那么就会显示是admin, 如果有的话, 则会显示是这个用户发出的
					"ext": {
						"msg": msg,
						"from": fromuserId
					}
				},
				success: function(httpResponse) {
					res.success('发送成功');
				},
				error: function(httpResponse) {
					if (httpResponse.status == 401) {
						getHXToken();
					}
					res.error('发送失败');
				}
			});
		},
		error: function() {
			res.error('发送失败');
		}
	})
}

/* 
 *发送系统消息
 *params:
 		touserId:发送给的Id
 		type: defult:0,非必须,默认为普通消息，msg必填.    1：欢迎消息  2：警告消息  3.投诉反馈的消息  4.禁言消息
*/

function sendSysMsg(req, res) {
	var touserId = req.params.touserId;
	var touserIds = [];
	if ((typeof touserId == 'object') && touserId.constructor == Array) {
		touserIds = touserId;
	} else {
		touserIds.push(touserId);
	}
	var type = req.params.type || 0
	var msg = req.params.msg || "";
	if (type == 1) {
		msg = "感谢您成为无独团会员。无独团是国内唯一的会员试恋制脱单俱乐部，致力于建立一个纯粹的环境，帮助85和90后追求理想爱情。现在您可以查看所有会员资料，真诚地向对方介绍自己，努力开始第一场试恋！加油!"
	} else if (type == 2) {
		msg = "您被多次举报，经核实您有谩骂色情/裸聊/垃圾广告/政治敏感行为。口袋恋人拒绝上述任何行为，请注意一下哒。若情节严重将按照《用户协议》封禁您的账户，并不做另行通知。么么哒～"
	} else if (type == 3) {
		msg = "你举报用户发送不良消息，我们审核后会从严处理，还你一片健康的恋爱环境。举报关系着别人的名誉，要负责的奥，请谨慎对待。"
	} else if (type == 4) {
		msg = "有人举报你传播不良信息，经过我们严格认真审查，本着净化聊天环境的愿景，特此对你实行一天的禁言，在这段时间通话、聊天功能将不能使用。亲爱的请走心哦。"
	} else if (type == 5) {
		msg = "我们已经收到您的投诉消息，核实后会对ta做出处理，结果会适时反馈给您。"
	}

	var tokenQuery = new AV.Query(models.HXToken);
	tokenQuery.descending("createdAt");
	tokenQuery.find({
		success: function(results) {
			var token = results[0].get('token');
			// 发送会话消息
			if (touserIds.length <= 20) {
				_sendMsg(token, touserIds, msg);
			} else {
				var arrays = _sliceArray(touserIds, 20);
				for (var i = 0; i < arrays.length; i++) {
					_sendMsg(token, arrays[i], msg);
				}
			}
			res.success('发送成功');
		},
		error: function() {
			res.error('发送失败');
		}
	})
}

function _sliceArray(array, num) {
	var arrays = []
	var count = array.length % num == 0 ? array.length / num : array.length / num + 1;
	for (var i = 0; i < count; i++) {
		var index = i * num;
		var temparr = [];
		var j = 0;
		while (j < num && index < array.length) {
			temparr.push(array[index++]);
			j++;
		}
		arrays.push(temparr);
	}
	return arrays;
}

function _sendMsg(token, touserIds, msg) {
	AV.Cloud.httpRequest({
		method: 'POST',
		url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/messages',
		headers: {
			"Content-Type": "application/json",
			"Authorization": "Bearer " + token
		},
		body: {
			"target_type": "users", // users 给用户发消息, chatgroups 给群发消息
			"target": touserIds, // 注意这里需要用数组,数组长度建议不大于20, 即使只有一个用户,   
			// 也要用数组 ['u1'], 给用户发送时数组元素是用户名,给群组发送时  
			// 数组元素是groupid
			"msg": {
				"type": "txt",
				"msg": msg //消息内容，参考[聊天记录](http://www.easemob.com/docs/rest/chatmessage/)里的bodies内容
			},
			"from": "MLSYSTEM", //表示这个消息是谁发出来的, 可以没有这个属性, 那么就会显示是admin, 如果有的话, 则会显示是这个用户发出的  		    	    
		},
		success: function(httpResponse) {},
		error: function(httpResponse) {}
	});
}

function sendRecommendMsg(req, res) {
	// var query = new AV.Query(models.MLUser);
	// var touserIds=[];
	// query.equalTo("isUserInited",1);
	// query.find({
	// 	success:function(users){
	// for(var i=0;i<users.length;i++){
	// 	touserIds.push(users[i].id);
	// }
	// var tokenQuery = new AV.Query(models.HXToken);
	//                tokenQuery.descending("createdAt");
	// tokenQuery.find({
	//    success:function(results){
	//    	var token = results[0].get('token');
	//    	// 发送会话消息
	//    	var arrays = _sliceArray(touserIds, 20);
	//    	for(var i = 0;i<arrays.length;i++){
	//    		_sendRecomendMsg(token,arrays[i]);
	//    	}    	
	//   		res.success('发送成功');	

	//    },
	//    error:function(){
	//    	res.error('发送失败');
	//    }
	AV.Push.send({
		channels: ["public"],
		data: {
			action: constant.NEW_RECOMMEND_PUSH,
			alert: "口袋恋人给你了新的推荐",
		}
	});
	// 	    res.success('发送成功');	
	// 	},
	// 	error:function(error){
	// 		res.error('发送失败');	
	// 	}
	// })
}



function _sendRecomendMsg(token, touserIds) {
	AV.Cloud.httpRequest({
		method: 'POST',
		url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/messages',
		headers: {
			"Content-Type": "application/json",
			"Authorization": "Bearer " + token
		},
		body: {
			"target_type": "users", // users 给用户发消息, chatgroups 给群发消息
			"target": touserIds, // 注意这里需要用数组,数组长度建议不大于20, 即使只有一个用户,   
			// 也要用数组 ['u1'], 给用户发送时数组元素是用户名,给群组发送时  
			// 数组元素是groupid
			"msg": {
				"type": "cmd",
				"action": "com.pocketsweet.RECOMMENT"
			},
			"from": "MLSYSTEM",
			"ext": {
				"msg": "口袋恋人发布了一篇新的推荐哦，快去看看吧"
			}
		},
		success: function(httpResponse) {
			//res.success('发送成功');
		},
		error: function(httpResponse) {
			//res.error('发送失败');		      
		}
	});
}

function sendUpdateMsg(req, res) {
	touserIds = req.params.touserIds;
	if (touserIds.length == 0) {
		return;
	}
	var ids = [];
	for (i = 0; i < touserIds.length; i++) {
		if (touserIds[0] != "MLSYSTEM" && touserIds[0] != "mlsystem") {
			ids.push(touserIds[i]);
		}
	}
	fromuserId = req.params.fromuserId;
	var tokenQuery = new AV.Query(models.HXToken);
	tokenQuery.descending("createdAt");
	tokenQuery.find({
		success: function(results) {
			var token = results[0].get('token');
			// 发送会话消息
			AV.Cloud.httpRequest({
				method: 'POST',
				url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/messages',
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer " + token
				},
				body: {
					"target_type": "users", // users 给用户发消息, chatgroups 给群发消息
					"target": ids, // 注意这里需要用数组,数组长度建议不大于20, 即使只有一个用户,   
					// 也要用数组 ['u1'], 给用户发送时数组元素是用户名,给群组发送时  
					// 数组元素是groupid
					"msg": {
						"type": "cmd",
						"action": "com.pocketsweet.UPDATE_PROFILE"
					},
					"from": fromuserId, //表示这个消息是谁发出来的, 可以没有这个属性, 那么就会显示是admin, 如果有的话, 则会显示是这个用户发出的 		    	    
				},
				success: function(httpResponse) {
					res.success('发送成功');
				},
				error: function(httpResponse) {
					if (httpResponse.status == 401) {
						getHXToken();
					}
					res.error('发送失败');
				}
			});
		},
		error: function() {
			res.error('发送失败');
		}
	})
}

function sendCallMsg(req, res) {
	userId = req.params.userId;
	touserId = req.params.touserId;
	AV.Push.send({
		channels: [touserId],
		data: {
			action: "com.pocketsweet.NEW_CALL",
			userId: userId,
			alert: "给你打电话",
		}
	});
}

function sendSysSms(req, res) {
	var phone = req.params.phone;
	var tmpName = req.params.tmpName;
	var name = req.params.name;
	var reason = req.params.reason || "";

	if (reason != "") {
		AV.Cloud.requestSmsCode({
			mobilePhoneNumber: phone,
			template: tmpName,
			reason: reason
		}).then(function() {
			//发送成功
			res.success('发送成功');
		}, function(err) {
			//发送失败
			res.error(err);
		});

	} else {
		AV.Cloud.requestSmsCode({
			mobilePhoneNumber: phone,
			template: tmpName,
			name: name
		}).then(function() {
			//发送成功
			res.success('发送成功');
		}, function(err) {
			//发送失败
			res.error(err);
		});
	}
}

function checkOnlineStatus(req, res) {
	var userId = req.params.userId;
	var tokenQuery = new AV.Query(models.HXToken);
	tokenQuery.descending("createdAt");
	tokenQuery.find({
		success: function(results) {
			var token = results[0].get('token');
			// 发送会话消息
			AV.Cloud.httpRequest({
				method: 'GET',
				url: 'https://a1.easemob.com/xiaocan/' + constant.APP_NAME + '/users/' + userId + '/status',
				headers: {
					"Content-Type": "application/json",
					"Authorization": "Bearer " + token
				},
				success: function(httpResponse) {
					res.success(httpResponse.data.data[userId]);
				},
				error: function(httpResponse) {
					res.success("shibai");
				}
			});
		},
		error: function() {
			res.error('发送失败');
		}
	})
}

function BalanceAccount(req, res) {
	var price = req.params.price || 0;
	var userId = req.params.userId;
	var userQuery = new AV.Query(models.MLUser);
	userQuery.get(userId, {
		success: function(user) {
			var balance = user.get('balance') + price;
			user.set('balance', parseFloat(balance.toFixed(2)));
			user.save(null, {
				success: function(user) {
					res.success('转账成功');
				},
				error: function(user, error) {
					res.error(error);
				}
			})
		},
		error: function(error) {
			res.error('转账失败');
		}
	})
}

exports.sendCallMsg = sendCallMsg;
exports.sendFriendApplyMsgShow = sendFriendApplyMsgShow;
exports.sendSweetApplyCMDMsg = sendSweetApplyCMDMsg;
exports.sendSweetApplyMsg = sendSweetApplyMsg;
exports.getHXToken = getHXToken;
exports.register = register;
exports.sendChatApplyMsg = sendChatApplyMsg;
exports.sendFriendApplyMsg = sendFriendApplyMsg
exports.sendChatAgreeMsg = sendChatAgreeMsg;
exports.transferAccount = transferAccount;
exports.newTransferAccount = newTransferAccount;
exports.BalanceAccount = BalanceAccount;
exports.sendNewLikerMsg = sendNewLikerMsg;
exports.sendSysMsg = sendSysMsg;
exports.sendUpdateMsg = sendUpdateMsg;
exports.sendRecommendMsg = sendRecommendMsg;
exports.sendSysSms = sendSysSms;
exports.checkOnlineStatus = checkOnlineStatus;